package com.pactera.miyuangroup.vo.convertor;

import com.baomidou.mybatisplus.plugins.Page;
import com.pactera.miyuangroup.db.entity.LoginUser;
import com.pactera.miyuangroup.vo.request.web.AddUserRequest;
import com.pactera.miyuangroup.vo.response.web.QueryUserDetailsRes;
import com.pactera.miyuangroup.vo.response.User;
import com.pactera.miyuangroup.vo.response.web.UserListRes;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * @author Wangwu
 * @create 2018-02-08 下午5:00
 **/
//设置sping支持@Autowired
@Mapper(componentModel = "spring")
public interface LoginUserConvert {

//    LoginUserConvert INSTANCE = Mappers.getMapper(LoginUserConvert.class);
//
//    AttendanceUserInfo convert2Do(AttendanceUserDo attUser);
//
//    List<AttendanceUserInfo> convert2Dos(List<AttendanceUserDo> attUsers);

    //支持多对象合并
//    @Mappings({
//            @Mapping(source = "modifyTime",target = "approvalTime")
//    })
//    GetAttendanceInfoRes convert2Res(AttendanceUser attUser);


    UserListRes convert2Res(LoginUser loginUser);

    //支持多对象合并
    @Mappings({
            @Mapping(source = "userName", target = "name"),
            @Mapping(source = "organizationId", target = "orgId"),
            @Mapping(source = "phone", target = "phone"),
            @Mapping(source = "jobNumber", target = "jobNumber"),
            @Mapping(source = "name", target = "username")
    })
    User convert2LoginUser(LoginUser loginUser);
    List<User> convert2LoginUser(List<LoginUser> loginUser);

    Page<UserListRes> convert2ResList(Page<LoginUser> loginUsers);


    //支持多对象合并
    @Mappings({
            @Mapping(source = "password", target = "userPassword")
    })
    LoginUser convert2AddUser(AddUserRequest req);

    //支持多对象合并
    @Mappings({
            @Mapping(source = "req.password", target = "userPassword"),
            @Mapping(source = "req.userName", target = "userName"),
            @Mapping(source = "req.name", target = "name"),
            @Mapping(source = "req.organizationId", target = "organizationId"),
    })
    LoginUser convert2AddUser(AddUserRequest req, LoginUser loginUser);

    //支持多对象合并
    @Mappings({
            //@Mapping(source = "userPassword", target = "password")
    })
    QueryUserDetailsRes convert2QueryUserDetails(LoginUser req);
}
